package com.gitee.yannzh.rune.support.crud;

import cn.hutool.extra.servlet.ServletUtil;
import com.gitee.yannzh.rune.support.web.JsonServletRequestWrapper;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: yann
 * @description: 请求参数工具类
 * @date：2024-01-01
 */
@Slf4j
public class WebUtil {


    public static <T> T bindRequestParameter(HttpServletRequest request, Class<T> clazz) throws Exception {
        if (request == null || clazz == null) {
            return null;
        }
        if (!(request instanceof JsonServletRequestWrapper)) {
            request = new JsonServletRequestWrapper(request);
        }
        return ServletUtil.toBean(request, clazz, true);
    }

}
